home *** CD-ROM | disk | FTP | other *** search
- Path: yellow59.nada.kth.se!md94-pst
- From: Per Steneskog <md94-pst@nada.kth.se>
- Newsgroups: comp.lang.c
- Subject: How to give functions as parameters?
- Date: Tue, 30 Jan 1996 22:42:30 +0100
- Message-ID: <Pine.SUN.3.91N2x.960130222756.11581A-100000@yellow59.nada.kth.se>
- NNTP-Posting-Host: yellow59.nada.kth.se
- Mime-Version: 1.0
- Content-Type: TEXT/PLAIN; charset=ISO-8859-1
- Content-Transfer-Encoding: 8BIT
-
-
- I have a little problem, I dont know how to send a fuction,
- as a parameter to another function..
-
-
-
- #include <stdio.h>
-
- void
- do_it(void (*it)())
- {
- ((*(it))());
- }
-
-
- void
- do_me(
- void)
- {
- printf("Testing!");
- }
-
-
- int
- main(
- void)
- {
- do_it(do_me()); /* ERROR-COMPILE LINE */
- }
-
-
-
- Short explaination: From main(), do_it() should be called with
- the parameter (and function) do_me(). (Pretty obvious :)
-
- When I try to compile this, i got the following error message: (gcc)
- In function `main':
- invalid use of void expression
-
- My question is, what should I write instead of that line in main()?
-
-
- THANKS everyone out there!
-
-
- /// Per Steneskog / +46 8 358552 (+1 GMT) ///
- /// LinnĪs v. 10 B / md94-pst@nada.kth.se ///
- /// 191 47 Sollentuna / http://www.nada.kth.se/~md94-pst/ ///
- /// Sweden / (last WWW-change 2 years ago :) ///
-